/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package sheldon;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;


public class SheldonTela extends javax.swing.JFrame {

    
    
    Integer posicao;
    List<Boneco> lista;
        
    public SheldonTela() {
        initComponents();
        lista = new ArrayList<Boneco>();
        posicao = 0;
        
   
    }
    
    private void limpar(){
        txtNome.setText(null);
        txtNome1.setText(null);
        txtNome2.setText(null);    
        txtNome3.setText(null);    
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        Primeiro = new javax.swing.JButton();
        Anterior = new javax.swing.JButton();
        Proximo = new javax.swing.JButton();
        Ultimo = new javax.swing.JButton();
        TxtNome = new javax.swing.JLabel();
        TxtDA = new javax.swing.JLabel();
        TxtSP = new javax.swing.JLabel();
        txtNome = new javax.swing.JTextField();
        txtNome1 = new javax.swing.JTextField();
        txtNome2 = new javax.swing.JTextField();
        TxtEditora = new javax.swing.JLabel();
        txtNome3 = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        TxtExcluir = new javax.swing.JButton();
        TxtCadastrar = new javax.swing.JButton();
        TxtConsultar = new javax.swing.JButton();
        TxtLimpar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Arial Black", 0, 12)); // NOI18N
        jLabel1.setText("Cadastro de Bonecos");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Navegação"));

        Primeiro.setText("Primeiro");
        Primeiro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PrimeiroActionPerformed(evt);
            }
        });

        Anterior.setText("Anterior");
        Anterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AnteriorActionPerformed(evt);
            }
        });

        Proximo.setText("Próximo");
        Proximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ProximoActionPerformed(evt);
            }
        });

        Ultimo.setText("Ultimo");
        Ultimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                UltimoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addComponent(Primeiro)
                .addGap(18, 18, 18)
                .addComponent(Anterior)
                .addGap(18, 18, 18)
                .addComponent(Proximo)
                .addGap(18, 18, 18)
                .addComponent(Ultimo)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Primeiro)
                    .addComponent(Anterior)
                    .addComponent(Proximo)
                    .addComponent(Ultimo))
                .addGap(0, 11, Short.MAX_VALUE))
        );

        TxtNome.setText("Nome:");

        TxtDA.setText("Data de apariciação:");

        TxtSP.setText("Super Poder:");

        txtNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNomeActionPerformed(evt);
            }
        });

        txtNome1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNome1ActionPerformed(evt);
            }
        });

        txtNome2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNome2ActionPerformed(evt);
            }
        });

        TxtEditora.setText("Editora:");

        txtNome3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNome3ActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        TxtExcluir.setText("Excluir");
        TxtExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TxtExcluirActionPerformed(evt);
            }
        });

        TxtCadastrar.setText("Cadastrar");
        TxtCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TxtCadastrarActionPerformed(evt);
            }
        });

        TxtConsultar.setText("Consultar");
        TxtConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TxtConsultarActionPerformed(evt);
            }
        });

        TxtLimpar.setText("Limpar");
        TxtLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TxtLimparActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(TxtCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(TxtExcluir)
                .addGap(18, 18, 18)
                .addComponent(TxtConsultar)
                .addGap(18, 18, 18)
                .addComponent(TxtLimpar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxtExcluir)
                    .addComponent(TxtCadastrar)
                    .addComponent(TxtConsultar)
                    .addComponent(TxtLimpar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(148, 148, 148)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(65, 65, 65)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(TxtDA)
                            .addComponent(TxtNome)
                            .addComponent(TxtSP)
                            .addComponent(TxtEditora))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNome)
                            .addComponent(txtNome1)
                            .addComponent(txtNome2)
                            .addComponent(txtNome3))))
                .addGap(108, 108, 108))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(31, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(44, 44, 44))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxtNome)
                    .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxtDA)
                    .addComponent(txtNome1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxtSP)
                    .addComponent(txtNome2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxtEditora)
                    .addComponent(txtNome3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(23, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void PrimeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PrimeiroActionPerformed
                
        if(lista.size()>0){
        
            posicao = 0;
        
            Boneco cadastro = lista.get(0);
            //Atribuir os textos conforme o item da minha lista
            txtNome.setText(cadastro.getNome());
            txtNome1.setText(cadastro.getData_aparicao());
            txtNome2.setText(cadastro.getEditora());
            txtNome3.setText(cadastro.getSuper_poder());
        }  
    }//GEN-LAST:event_PrimeiroActionPerformed

    private void txtNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNomeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNomeActionPerformed

    private void txtNome1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNome1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNome1ActionPerformed

    private void txtNome2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNome2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNome2ActionPerformed

    private void txtNome3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNome3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNome3ActionPerformed

    private void TxtExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TxtExcluirActionPerformed
        lista.remove(lista.get(posicao));
        limpar();
    }//GEN-LAST:event_TxtExcluirActionPerformed

    private void TxtCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TxtCadastrarActionPerformed
        Boneco b = new Boneco();
        b.setNome(txtNome.getText());
        b.setData_aparicao(txtNome1.getText());
        b.setSuper_poder(txtNome2.getText());
        b.setEditora(txtNome3.getText());
        
        lista.add(b);
        limpar();
        
        
    }//GEN-LAST:event_TxtCadastrarActionPerformed

    private void TxtLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TxtLimparActionPerformed
        limpar();
    }//GEN-LAST:event_TxtLimparActionPerformed

    private void AnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AnteriorActionPerformed
        if(lista.size()>0){
        
            posicao = posicao - 1;
        
            Boneco cadastro = lista.get(posicao);
            txtNome.setText(cadastro.getNome());
            txtNome1.setText(cadastro.getData_aparicao());
            txtNome2.setText(cadastro.getEditora());
            txtNome3.setText(cadastro.getSuper_poder());
            
        }
    }//GEN-LAST:event_AnteriorActionPerformed

    private void ProximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ProximoActionPerformed
            if(lista.size()>0){
        
            posicao = posicao + 1;
            
            Boneco cadastro = lista.get(posicao);
            txtNome.setText(cadastro.getNome());
            txtNome1.setText(cadastro.getData_aparicao());
            txtNome2.setText(cadastro.getEditora());
            txtNome3.setText(cadastro.getSuper_poder());
            }       
    }//GEN-LAST:event_ProximoActionPerformed

    private void UltimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UltimoActionPerformed
        if(lista.size()>0){
        
            posicao = lista.size() - 1;
        
            Boneco cadastro = lista.get(posicao);
            txtNome.setText(cadastro.getNome());
            txtNome1.setText(cadastro.getData_aparicao());
            txtNome2.setText(cadastro.getEditora());
            txtNome3.setText(cadastro.getSuper_poder());
        }
    }//GEN-LAST:event_UltimoActionPerformed

    private void TxtConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TxtConsultarActionPerformed
        String nome = JOptionPane.showInputDialog("Digite o nome a ser pesquisado");
        
        Boolean encontrou = false;
        
        for (Boneco boneco : lista) {
            if(nome.equals(boneco.getNome())){
                encontrou = true;
            
                txtNome.setText(boneco.getNome());
                txtNome1.setText(boneco.getData_aparicao());
                txtNome2.setText(boneco.getEditora());
                txtNome3.setText(boneco.getSuper_poder());
            
                break;
            }
        }
            
        if(encontrou == true){
            JOptionPane.showMessageDialog(null, "Achou!");
        }
        else{
            JOptionPane.showMessageDialog(null, "Não Achou!");
        }
         
        
    }//GEN-LAST:event_TxtConsultarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SheldonTela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SheldonTela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SheldonTela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SheldonTela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SheldonTela().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Anterior;
    private javax.swing.JButton Primeiro;
    private javax.swing.JButton Proximo;
    private javax.swing.JButton TxtCadastrar;
    private javax.swing.JButton TxtConsultar;
    private javax.swing.JLabel TxtDA;
    private javax.swing.JLabel TxtEditora;
    private javax.swing.JButton TxtExcluir;
    private javax.swing.JButton TxtLimpar;
    private javax.swing.JLabel TxtNome;
    private javax.swing.JLabel TxtSP;
    private javax.swing.JButton Ultimo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField txtNome;
    private javax.swing.JTextField txtNome1;
    private javax.swing.JTextField txtNome2;
    private javax.swing.JTextField txtNome3;
    // End of variables declaration//GEN-END:variables

    
}
